package top.wnma.crud.dao.impl;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import top.wnma.crud.dao.StaffDao;
import top.wnma.crud.pojo.Staff;

@Repository
public class StaffDaoImpl extends HibernateDaoSupport  implements StaffDao {

	@Resource
	public void setMySessionFactory(SessionFactory sessionFactory) {
		super.setSessionFactory(sessionFactory);
	}
	
	public void save(Staff staff) {
		this.getHibernateTemplate().save(staff);
	}

	public void delete(Staff staff) {

		this.getHibernateTemplate().delete(staff);
	}

	public void update(Staff staff) {

		this.getHibernateTemplate().update(staff);
	}

	public void saveOrUpdate(Staff staff) {

		this.getHibernateTemplate().saveOrUpdate(staff);
	}

	public Staff findById(Serializable id) {
		return this.getHibernateTemplate().get(Staff.class, id);
	}

	public List<Staff> findAll() {
		String hql="from Staff";
		return (List<Staff>) this.getHibernateTemplate().find(hql);
	}
	
	

}
